<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->increments('id');
            $table->char('order_code', 24)->comment('订单号码')->unique();
            $table->integer('member_id')->unsigned()->comment('创建订单的用户')->index();
            $table->integer('store_id')->unsgined()->comment('店铺 ID')->index();
            $table->integer('provider_id')->unsigned()->comment('供应商用户 ID')->index();
            $table->boolean('status')->comment('订单状态')->index();
            $table->decimal('total_amount', 10, 2)->comment('订单总金额（该值仅作缓存使用）');
            $table->timestamp('pay_time')->comment('支付时间')->index();
            $table->tinyInteger('pay_type')->comment('支付方式')->unsigned()->index();
            $table->text('message')->comment('订单留言');

            $table->timestamp('ship_time')->comment('发货时间')->index();
            $table->timestamp('finish_time')->comment('完成时间')->index();
            $table->decimal('logistics_price')->comment('物流报价');
            $table->string('logistics_number')->comment('物流单号')->index();
            $table->string('logistics_receipts')->comment('物流单据');
            $table->string('delivery_address')->comment('收货地址');
            $table->string('consignee')->comment('收货人');
            $table->string('consignee_information')->comment('收货人详细信息，可利用 json 格式格式化数据');

            $table->boolean('invoice_type')->comment('发票类型');
            $table->string('invoice_title')->comment('发票抬头');
            $table->text('invoice_content')->comment('发票详细信息，对于存在相当多发票信息时，可以用该字段保存 json 格式数据');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('orders');
    }
}
